/**
 * Created by tanbingqin on 2020/6/30.
 */
import { messages } from "share/common";
import React from 'react'
import { connect } from 'react-redux'
import requestService from 'containers/request/request.service'
import BaseRequestDetailComp from "containers/request/base-request-detail";
import RequestDetailComp from "containers/request/slide/request-detail";
import Condition from 'components/condition';
const If = Condition.If;
import { Spin } from 'antd'

class RequestDetail extends React.Component{
  constructor(props) {
    super(props);
    this.state = {
      isNewTravelCard: false, //是否是差旅行程卡片模式
      isInitOver: false //是否初始化入口判断结束
    }
  }

  componentWillMount(){}

  componentDidMount(){
    this.getFormInfo();
  }

  getFormInfo = () => {
    const { params } = this.props;
    requestService.getCustomForm(params.formOID).then(res => {
      if (res.data.formType === 2001) {
        this.getInfo();
      } else {
        this.setState({isInitOver: true});
      }
    });
  };

  getInfo = () => {
    const { applicationOID } = this.props.params;
    //获取差旅单详情
    requestService.getRequestDetail(applicationOID).then(res => {
      this.setState({isInitOver: true, isNewTravelCard: res.data.enableCustomBudget});
    });
  };

  render() {
    const { isNewTravelCard, isInitOver } = this.state;
    return (
      <div>
        <If value={isInitOver}>
          <If value={isNewTravelCard}>
            <RequestDetailComp {...this.props}/>
          </If>
          <If value={!isNewTravelCard}>
            <BaseRequestDetailComp {...this.props}/>
          </If>
        </If>
        <If value={!isInitOver}>
          <Spin spinning={true} />
        </If>
      </div>
    )
  }
}

RequestDetail.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps(state) {
  return {}
}

export default connect(mapStateToProps)(RequestDetail)
